<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../../css/api.css" />
		<link rel="stylesheet" type="text/css" href="../../css/style.css" />
		<link rel="stylesheet" type="text/css" href="../../css/btnplus.css" />
		<style type="text/css">
			html,body{
				background-color: #F7F8FA;
				overflow-y: auto;
				-webkit-overflow-scrolling:touch;
			}
			.order_list{ padding: 10px 15px;}
			.order_list li{ margin-bottom: 10px; background-color: #fff; padding: 0 10px; border-radius: 4px; overflow: hidden;}
			.order_list .title{ position:relative; height: 40px; line-height: 40px; font-size: 13px; color: #999;}
			.order_list .title::after{ position:absolute; content: ""; left: 0; right: 0; bottom: 0; border-bottom: 1px #d4d4d4 solid; transform: scaleY(0.5);}
			.order_list .title p{ float:left;}
			.order_list .title i{ float: right; color: #1c63fa; font-size: 12px;}
			.order_list .con{ padding: 5px 0 15px;}
			.order_list .con h4{ display:block; font-size: 18px; font-weight: 500; color: #333; line-height: 35px;}
			.order_list .con p{ font-size: 14px; color: #5D5D5D; line-height: 18px;}
			.order_list .con i{ float: left; border-radius: 2px; margin-right: 12px; line-height: 16px; font-size: 12px; padding: 0 6px;}
			.order_list .con img{ display:inline-block; vertical-align: top; height: 5px; margin: 14px 5px 0;}
			.s_01{border: 1px #CF4242 solid; color: #CF4242;}
			.s_02{border: 1px #69C8A2 solid; color: #69C8A2;}
			.s_03{border: 1px #3262F1 solid; color: #3262F1;}
			.sk-three-bounce {
			  margin: 0 auto;
			  width: 80px;
			  text-align: center; }
			  .sk-three-bounce .sk-child {
				width: 13.5px;
				height: 13.5px;
				background-color: #3262F1;
				border-radius: 100%;
				display: inline-block;
				-webkit-animation: sk-three-bounce 1.4s ease-in-out 0s infinite both;
						animation: sk-three-bounce 1.4s ease-in-out 0s infinite both; }
			  .sk-three-bounce .sk-bounce1 {
				-webkit-animation-delay: -0.32s;
						animation-delay: -0.32s; }
			  .sk-three-bounce .sk-bounce2 {
				-webkit-animation-delay: -0.16s;
						animation-delay: -0.16s; }

			@-webkit-keyframes sk-three-bounce {
			  0%, 80%, 100% {
				-webkit-transform: scale(0);
						transform: scale(0); }
			  40% {
				-webkit-transform: scale(1);
						transform: scale(1); } }

			@keyframes sk-three-bounce {
			  0%, 80%, 100% {
				-webkit-transform: scale(0);
						transform: scale(0); }
			  40% {
				-webkit-transform: scale(1);
						transform: scale(1); }
			}
			.more{ padding: 1.20rem 0; text-align: center; font-size: 0.26rem; color: #999; line-height: 0.60rem;}
			.display-none{ display:none; }
			.text-center { text-align: center !important; }
		</style>
	</head>
	<body>
		<div id="result">
		<div class="order_list">
			<ul id="billlist">
				
			</ul>
			<script id="billlist_template" type="text/template">
				{{ for (var i = 0, len = it.length; i < len; i++) { }}
				<li tapmode="lipress" onclick="openNavWin('#ddd','billdetail_win','billdetail_frm.html','运单详情',false,false,true,[],{billid:{{=it[i].id}}});">
					<div class="title">
						<p>{{=it[i].createtime}}</p>
						{{? it[i].status == 1}}
						<i>进行中</i>
						{{?? it[i].status == 2}}
						<i>待确认</i>
						{{?? it[i].status == 3}}
						<i>已完成</i>
						{{?}}
					</div>
					<div class="con">
						<h4>{{=it[i].sendaddress}} <img src="../../image/img_21.png" alt="" /> {{=it[i].destaddress}}</h4>
						<p class="clearfix"><i class="s_0{{=it[i].loadingdatestatus}}">{{=it[i].loadingdate}}装车</i>{{=it[i].cartype}}/{{=it[i].carlen}}/{{=it[i].weightv}}/{{=it[i].goodstype}}</p>
					</div>
				</li>
				{{ } }}
			</script>
		</div>
		</div>
		<div class="text-center display-none" style="padding: 110px 0 !important;" id="divnodata">
			<div class="text-center"><img src="../../image/nofound.png" style="margin:0 auto;width:41px;height:auto;"></div>
			<p class="text-center" style="font-size:12px;color:#9f9f9f;margin-top:15px;">暂时没有运单信息</p>
		</div>
	</body>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/app.js"></script>
	<script type="text/javascript" src="../../script/doT.js"></script>
	<script type="text/javascript">
		var page = 1;
		var params = {
			where: {
				status: 0,
				billtype: ''
			},
			page: 1
		};
		var UILoading;
		apiready = function() {
			api.parseTapmode();
			UILoading = api.require('UILoading');
			$api.css($api.dom('#result'), 'display: none');
			showloading();
			getJsonFromAPI();
			params.where.status = api.pageParam.status;
			params.where.billtype = api.pageParam.billtype;
			
			var transformarr = [];
			for(var i=1; i<24; i++)
			{
				var index = i < 10 ? '0'+i : i;
				transformarr.push('widget://image/UIPullRefreshImg/pull_end_image_frame_'+index+'.png');
			}
			api.setCustomRefreshHeaderInfo({
				bgColor : '#F7F8FA',
				image : {
					pull : 'widget://image/UIPullRefreshImg/pull.png',
					transform : transformarr,
					load : transformarr
				}
			}, function(ret, err) {
				page = 1;
				getJsonFromAPI();
				setTimeout(function() {
					api.refreshHeaderLoadDone();
				}, 3000)
			});
			
			api.addEventListener({
				name:"scrolltobottom"
			},function(ret,err){
				getJsonFromAPI();
			});
			api.addEventListener({
				name : 'refreshbill'
			}, function(ret, err) {
				refreshPage();
				
			});
			api.addEventListener({
				name : 'reloadpage'
			}, function(ret, err) {
				refreshPage();				
			});
		}
		function refreshPage() {
			page = 1;
			getJsonFromAPI();
		}
		function getJsonFromAPI() {
			//从接口获取查询数据
			api.getPrefs({
				key: 'user_info'
			}, function(ret, err) {
				if (ret.value) {
					var userinfo = JSON.parse(ret.value);
					api.ajax({
						url: ApiUrl + '/v1/bill/'+page+'/'+ $api.jsonToStr(params),
						method: 'get',
						cache: false,
						timeout: 10,
						headers: {
							authorization: kAppKey+';'+userinfo.access_token+';'+userinfo.uid
						}
					}, function(ret, err) {
						hideloading();
						if(page == 1) {
							api.refreshHeaderLoadDone();
						}
						$api.css($api.dom('#result'), 'display: block');
						if (ret) {
							
							if(ret.list.length > 0)
							{
								$api.addCls($api.byId('divnodata'),'display-none');
								var isAppend = true;
								if(page==1)
								{
									isAppend = false;
								}
								page++;
								var billlist = ret.list;
								UpdateList('billlist','billlist_template',billlist,isAppend);
							}
							else
							{
								if(page==1)
								{
									UpdateList('billlist','billlist_template',ret.list,false);
									$api.removeCls($api.byId('divnodata'),'display-none');
								}
							}
							
						} else {
							if(err.statusCode==402)
							{
								Relogin();
							}
							else
							{
								console.log(JSON.stringify(err));
								toast('网络异常');
							}
						}
					});
				}
			});
		}
		//渲染数据
		function UpdateList(domId,templateId,jsondata,isAppend) {
			//console.log(JSON.stringify(jsondata));
			var act_content = $api.byId(domId);
			var tempFn = doT.template($api.byId(templateId).innerHTML);
			var resultText = tempFn(jsondata);
			//alert(isAppend);
			console.log(resultText);
			if(isAppend)
			{
				$api.append(act_content, resultText);
			}
			else
			{
				$api.html(act_content, resultText);
			}
			api.parseTapmode();
		}
	</script>
</html>